/**
 * 数组中只出现一次的数字
 * Created by JiaJia on 2019/6/10 0010.
 */
public class Code40 {
    /**
     * 逐位异或的方法，得到两个只出现一次的数字异或的结果
     * 再找到异或结果最右边的不为0的位置
     * 按该位的不同再将数组分为两类
     * 分别异或，各自找到只出现一次的数字
     */
    public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
        int diff = 0;
        for (int num : array)
            diff ^= num;
        diff &= -diff;
        for (int num : array) {
            if ((num & diff) == 0)
                num1[0] ^= num;
            else
                num2[0] ^= num;
        }
    }

}